package com.seveneight.baijiesteward.ui.main.presenter;

import android.content.Context;

import com.seveneight.baijiesteward.bean.UserBean;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.ui.main.contract.LoginContract;
import com.seveneight.baijiesteward.ui.main.model.LoginModel;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/2/23.
 */

public class LoginPresenter implements LoginContract.LoginPresenter {

    LoginContract.LoginView loginView;
    LoginContract.LoginModel loginModel;

    public LoginPresenter(LoginContract.LoginView loginView) {
        this.loginView = loginView;
        loginModel = new LoginModel();
    }

    @Override
    public void login(Context context, RequestBody body) {
        loginModel.login(context, body, new MyCallBack<UserBean>() {

            @Override
            public void onSuccess(UserBean userBean) {
                if (loginView!=null)
                    loginView.reBackkUser(userBean);
            }

            @Override
            public void onFailed() {

            }
        });
    }

    @Override
    public void getUserInfo(String message, Context context, RequestBody body) {
        loginModel.getUserInfo(message, context, body, new MyCallBack<UserBean>() {

            @Override
            public void onSuccess(UserBean userBean) {
                if (loginView!=null)
                    loginView.backUserInfo(userBean);
            }

            @Override
            public void onFailed() {

            }
        });
    }
}
